package com.york.learning.springbootlistenerdemo.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationListener;

public class MyApplicationStartedEventListener implements ApplicationListener<ApplicationStartingEvent> {
    private Logger logger = LoggerFactory.getLogger(MyApplicationStartedEventListener.class);

    @Override
    public void onApplicationEvent(ApplicationStartingEvent event) {
        SpringApplication app = event.getSpringApplication();
        // 不显示banner信息
        app.setBannerMode(Mode.OFF);
        // 这时logger还没有初始化，不能打印日志的
        logger.info("==MyApplicationStartedEventListener==");
        // 控制台可以输出
        System.out.println("==MyApplicationStartedEventListener==");
    }
}
